package com.lagou.edu.service.impl;

import com.lagou.edu.annotation.Autowired;
import com.lagou.edu.annotation.Service;
import com.lagou.edu.annotation.Transactional;
import com.lagou.edu.dao.IAccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.ITransferService;

/**
 * @author Kirito
 * @description:
 * @date 2020/04/04
 */
@Service
@Transactional
public class TransferServiceImpl implements ITransferService {

    // private IAccountDao accountDao = new JdbcAccountDaoImpl();

    //private IAccountDao accountDao = (IAccountDao) BeanFactory.getObject("accountDao");

    @Autowired
    private IAccountDao accountDao;

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        accountDao.updateAccountByCardNo(from);
        // int i = 1 / 0;
        accountDao.updateAccountByCardNo(to);
    }
}
